﻿#region Using
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
#endregion Using

namespace LloydGame
{
    public class ScreenComponentLobbyList : GameScreenComponent
    {
        #region Fields
        protected GamerCollection<NetworkGamer> m_gamers;
        protected Texture2D m_gamer_list_bg, m_gamer_list_ready, m_gamer_list_notready;
        #endregion Fields

        #region Constructor
        public ScreenComponentLobbyList(Vector2 p_pos, Vector2 p_size, Game p_game) :
            base("Lobby List", p_pos, p_size, p_game)
        {
            m_smallfont = ((Game1)p_game).menuFontSmall;

            m_gamer_list_bg = Texture2D.FromFile(((Game1)p_game).GraphicsDevice, "Content\\lobby_gamerlist_back.png");
            m_gamer_list_ready = Texture2D.FromFile(((Game1)p_game).GraphicsDevice, "Content\\lobby_gamerlist_ready.png");
            m_gamer_list_notready = Texture2D.FromFile(((Game1)p_game).GraphicsDevice, "Content\\lobby_gamerlist_notready.png");
        }
        #endregion

        #region Properties
        public GamerCollection<NetworkGamer> gamers { get { return m_gamers; } set { m_gamers = value; } }
        #endregion Properties

        #region Draw
        public override void Draw(SpriteBatch p_spritebatch, bool p_active)
        {
            // Debug
            //p_spritebatch.Draw(t_blanktex, new Rectangle((int)m_pos.X, (int)m_pos.Y, (int)m_size.X, (int)m_size.Y), Color.DimGray);

            int t_id = 0;
            float t_x, t_y;
            foreach (NetworkGamer t_gamer in m_gamers)
            {
                t_x = m_pos.X;
                t_y = m_pos.Y + t_id * 32;

                // Draw background
                p_spritebatch.Draw(m_gamer_list_bg, new Rectangle((int)t_x, (int)t_y, 512, 32), Color.White);

                // TODO: Draw ready flag
                if (t_gamer.IsReady)
                    p_spritebatch.Draw(m_gamer_list_ready, new Rectangle((int)t_x, (int)t_y, 32, 32), Color.White);
                else
                    p_spritebatch.Draw(m_gamer_list_notready, new Rectangle((int)t_x, (int)t_y, 32, 32), Color.White);

                // Draw gamertag
                p_spritebatch.DrawString(m_smallfont, t_gamer.Gamertag, new Vector2(t_x + 36, t_y + 6), Color.Black);
                p_spritebatch.DrawString(m_smallfont, t_gamer.Gamertag, new Vector2(t_x + 35, t_y + 5), Color.White);

                t_id++;
            }
            /*
            p_spritebatch.DrawString(m_normalfont, m_title, new Vector2(m_pos.X + 1, m_pos.Y + 1), Color.Black);
            if (m_active)
                p_spritebatch.DrawString(m_normalfont, m_title, m_pos, Color.DimGray);
            else
                p_spritebatch.DrawString(m_normalfont, m_title, m_pos, Color.White);
            */
        }
        #endregion
    }
}